package com.googlecode.scup.grammar;

import com.googlecode.scup.grammar.grammarspart.Rule;
import com.googlecode.scup.grammar.grammarspart.Symbol;
import com.googlecode.scup.grammar.grammarspart.Production;

import java.util.List;
import java.util.ArrayList;

public class ExtensionSimpleGrammar extends SimpleGrammar {
    public ExtensionSimpleGrammar(List<Rule> rules) {
        super(rules);
        createExtension();
    }

    public ExtensionSimpleGrammar(Grammar grammar) {
        super(grammar.getRules());
        createExtension();
    }

    private void createExtension() {
        //TODO: make somthing with it T_T
        Symbol oldBase = rules.get(0).getBase();
        List<Symbol> prod = new ArrayList<Symbol>();
        prod.add(oldBase);
        Production production = new Production(prod);
        List<Production> newProd = new ArrayList<Production>();
        newProd.add(production);

        Rule extensionRule = new Rule(new Symbol(oldBase.getName() + "1", false), newProd);
        rules.add(0, extensionRule);
    }

    public Rule getStartRule() {
        return rules.get(0);
    }
}
